package com.ycsj.goldmedalnewconcept.common.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ycsj.common.base.ViewHolder;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.common.bean.ChooseItem;

import java.util.List;

/**
 * 课文跟读展示答案选项的列表适配器
 * Created by Administrator on 2019/4/4 0004.
 */

public class FollowLvAdapter extends CommonAdapter<ChooseItem> {

    private Context context;

    public FollowLvAdapter(Context context, List<ChooseItem> datas, int layoutId) {
        super(context, datas, layoutId);
        this.context = context;
    }

    @Override
    public void convert(ViewHolder holder, ChooseItem chooseItem) {

        //最外层布局
        LinearLayout llOut = holder.getView(R.id.ll_out);

        //选项索引
        TextView tvIndex = holder.getView(R.id.tv_index);
        tvIndex.setText(chooseItem.index);

        //选项的内容
        TextView tvContent = holder.getView(R.id.tv_content);
        tvContent.setText(chooseItem.content);

        //对错的显示图标
        ImageView lvState = holder.getView(R.id.lv_state);

        if (chooseItem.isChoosed) {
            //选中
            lvState.setVisibility(View.VISIBLE);

            if (chooseItem.isRight) {
                //正确选项
                llOut.setBackgroundResource(R.drawable.ll_out_choosed);
                lvState.setImageResource(R.drawable.rightcloze);
                tvIndex.setTextColor(context.getResources().getColor(R.color.choosed));
                tvIndex.setBackgroundResource(R.drawable.item_choosed);

            } else {
                llOut.setBackgroundResource(R.drawable.ll_out_unchoosed);
                lvState.setImageResource(R.drawable.errorcloze);
                tvIndex.setTextColor(context.getResources().getColor(R.color.unchoosed));
                tvIndex.setBackgroundResource(R.drawable.item_unchoosed);
            }

        } else {
            //未选中
            tvIndex.setBackgroundResource(R.drawable.item_unchoosed);
            tvIndex.setTextColor(context.getResources().getColor(R.color.unchoosed));
            llOut.setBackgroundResource(R.drawable.ll_out_unchoosed);
            lvState.setVisibility(View.INVISIBLE);
        }


    }
}
